<?php
Yii::import('application.widgets.chart.AbstractPieChart');

class LoanBankChart extends AbstractPieChart{

	public $title='Loans by Bank';

	protected function getData(){
		$criteria=new CDbCriteria();
		$criteria->select='bank , count(*) as count';
		$criteria->group='bank';
		$commandBuilder= Yii::app()->db->getSchema()->getCommandBuilder();
		$command=$commandBuilder->createFindCommand(Loan::model()->getTableSchema(),$criteria);
		$row=$command->queryAll();
		$result=array();
		foreach ($row as $teamRow){
			$result[]=array('value'=>intval($teamRow['count']),'name'=>$teamRow['bank']);
		}
		return $result;
	}
}